package com.czy.util.json;

import com.czy.convert.Converter;
import com.czy.util.time.TimeFormat;
import com.czy.util.time.TimeUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.LocalDate;

/**
 * @author chenzy
 * @since 2023/6/6
 **/
public class SerializerLocalDate2Str extends JsonSerializer<LocalDate> implements Converter<LocalDate, String> {

    @Override
    public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeString(convert(value));
    }

    @Override
    public String convert(LocalDate source) {
        return TimeUtil.time2Str(source, TimeFormat.yyyy_MM_dd);
    }
}
